package com.sfac.springCloudAccount.service.impl;

import com.sfac.account.Role;
import com.sfac.springCloudAccount.dao.RoleDao;
import com.sfac.springCloudAccount.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * RoleService
 */
@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleDao roleDao;

	@Override
	public List<Role> getRoles() {
		return Optional.ofNullable(roleDao.getRoles()).orElse(Collections.emptyList());
	}

	@Override
	public List<Role> getRolesByUserId(int userId) {
		return Optional
				.ofNullable(roleDao.getRolesByUserId(userId))
				.orElse(Collections.emptyList());
	}
}
